//
//  DFUser.m
//  doubanFun
//
//  Created by bing on 16/3/22.
//  Copyright © 2016年 bing. All rights reserved.
//

#import "DFUser.h"

@implementation DFUser

- (instancetype)initWithDictionary:(NSDictionary *)dictionary {
    if (self = [super init]) {
        _token    = [dictionary stringForKey:@"token"];
        _email    = [dictionary stringForKey:@"email"];
        _userID   = [dictionary stringForKey:@"user_id"];
        _userName = [dictionary stringForKey:@"user_name"];
        _expire   = @([[dictionary stringForKey:@"expire"] integerValue]);
    }
    return self;
}

+ (instancetype)initWithDictionary:(NSDictionary *)dictionary {
    return [[self alloc] initWithDictionary:dictionary];
}

#pragma mark - NSCoding

- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:_token forKey:@"token"];
    [aCoder encodeObject:_email forKey:@"email"];
    [aCoder encodeObject:_userID forKey:@"userID"];
    [aCoder encodeObject:_userName forKey:@"userName"];
    [aCoder encodeObject:_expire forKey:@"expire"];
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super init]) {
        _token    = [aDecoder decodeObjectForKey:@"token"];
        _email    = [aDecoder decodeObjectForKey:@"email"];
        _userID   = [aDecoder decodeObjectForKey:@"userID"];
        _userName = [aDecoder decodeObjectForKey:@"userName"];
        _expire   = [aDecoder decodeObjectForKey:@"expire"];
    }
    return self;
}

@end
